global replica_dir="<add path to your working directory>"

global data_dir=	"$replica_dir/data"
global output_dir=	"$replica_dir/output"

use "$data_dir/slvl_fin.dta", clear  


/*----------------------------------------------------------------------------*/  

**# T.A5 Baseline check for teacher  variables

/*----------------------------------------------------------------------------*/


la var gender_tm1  "Teacher men, baseline"
la var tit_educ_tm1 "Education degree, baseline"
la var municip_tm1 "Municipal school, baseline"
la var rural_rbd_tm1 "Rural school, baseline"
la var multsch_tm1 	"Teach in multiple schools, baseline" 
la var tea_admin_tm1 "Administrative duties primarily, baseline"

la var horas_contrato_tm1 	"Contract hours, baseline"
la var tea_classhrs_tm1  	"Classroom teaching hours, baseline"
 
la var dropped_tm1  "Turnover: Lagged attrition, baseline"
la var newtea_tm1    "Turnover: Prop. new teachers, baseline"
la var exp_tm1   	"Teacher experience, baseline"
la var aep10_tm1  	"Prop. AEP certified, baseline"

la var treat25 "Full vs. Partial Bonus"
la var treat10 "Partial vs. No Bonus"

la var st_ind25 "100% vs. 60%"
la var st_ind10 "60% vs. none"


save "$data_dir/temp.dta", replace


/*----------------------------------------------------------------------------*/  



foreach i in 10 25{
	
use "$data_dir/temp.dta", clear

global indepvars "municip_tm1 rural_rbd_tm1 gender_tm1 tit_educ_tm1 permanent_tm1 tea_admin_tm1 multsch_tm1 horas_contrato_tm1 tea_classhrs_tm1 dropped_tm1 newtea_tm1 exp_tm1 aep10_tm1"
	

matrix define R = J(13, 4, .) // (#indepvars, #stats, missing values for all entries)

local label_st_ind`i': variable label st_ind`i'

	local k = 1

	foreach y of global indepvars {
		
		local label_`k': variable label `y'

		reg `y' treat`i' st_ind`i' st_ind`i'_sq inter`i' inter`i'_sq i.hg i.sned_yr if abs(st_ind`i') <= 1.5, vce(cluster rbd)
		
		matrix R[`k', 1] = r(table)[1,1] // rd estimate  
		matrix R[`k', 2] = r(table)[2,1] //se_ of rd estimate  
		matrix R[`k', 3] = r(table)[4,1] //p-value
		matrix R[`k', 4] = e(N) //N
		
		matrix list R
		local k = `k' + 1
		}

	matrix list R

preserve
	clear
	local t = `k' - 1
	svmat R
	gen R0 = ""
	forvalues k = 1 / `t' {
	replace R0 = "`label_`k''" if _n == `k'
	}
	order R0
	save "$data_dir/pre_results_`i'.dta", replace
restore

use "$data_dir/pre_results_`i'.dta", clear

rename (R0 R1 R2 R3 R4) (Variable CoefficientEstimate StandardError pvalue Observations)

cd "$output_dir"
dataout, save(pre_t_`i'.tex) tex dec(3) replace

erase "$data_dir/pre_results_`i'.dta"

} 


erase "$data_dir/temp.dta"

*----------------------------------   end








